package com.sufen.seckill.study.LeetCode;

/**
 * @Author sufen
 * @Date 2021/11/6 14:31
 * @Version 1.0
 * 功能描述：
 */
public class b_Offer_14_2_剪绳子2 {
    public int cuttingRope(int n) {
        if(n<=3){
            return n-1;
        }
        int a=n/3;
        int b=n%3;

        long res=1L;

        if(b==0){
            for(int i=0;i<a;i++){
                res=res*3%1000000007;
            }
            return (int)res;
        }else if(b==1){
            for(int i=0;i<a-1;i++){
                res=res*3%1000000007;
            }
            res=res*4%1000000007;
            return (int)res;
        }else{
            for(int i=0;i<a;i++){
                res=res*3%1000000007;
            }
            res=res*2%1000000007;
            return (int)res;
        }
    }
}
